Once upon a time in the magical land of Linux Networkville, there lived houses that needed addresses so the mailman (we call him "packets") could deliver messages!
But here's the tricky part: How do we know which houses are on the same street? And how do we know which neighborhood they belong to?
That's where three superhero friends come to save the day:
ifconfig or ip addr in the terminal!
Imagine every house in Computer World has a special address like 192.168.1.5. This is called an IP Address (Internet Protocol Address).
Just like your home address has:
π Street Name + House Number
An IP address has:
π Network Part (which neighborhood) + Host Part (which specific house)
Red = Network (Neighborhood) | Blue = Host (House Number)
The Network Mask is like a magical mask that shows us which part of the address is the neighborhood name and which is the house number!
Think of it like a stencil:
The mask 255.255.255.0 says: "The first three numbers are the neighborhood (network), and the last number is the house (host)!"
Green = Same street (network) | Pink = Different street
Now, imagine the neighborhood 192.168.1.0 has 256 houses (0-255). That's a LOT of houses! The mailman gets tired walking so far.
So we use a Subnet Mask to break the big neighborhood into smaller blocks (subnets)!
255.255.255.0255.255.255.128255.255.255.192It's like taking a big apartment building and dividing it into sections A, B, C, and D!
Computers don't speak numbers like 255 - they speak Binary (0s and 1s)!
Let's look at the mask 255.255.255.0 in binary:
See the pattern? 1s = Network, 0s = Host!
Writing 255.255.255.0 every time is tiring! Network engineers are lazy (in a smart way), so they invented CIDR!
CIDR stands for Classless Inter-Domain Routing, but we can call it "Counting the 1s"!
It's like writing "Dr." instead of "Doctor" - a quick shortcut!
ip addr and see inet 192.168.1.5/24, that /24 is the CIDR notation telling me the size of my neighborhood!"
So what's the difference between these three friends? Let's compare!
| Concept | Analogy | What It Does | Linux Use |
|---|---|---|---|
| Network Mask | Street Sign π | Shows network vs host boundary | Basic routing decisions |
| Subnet Mask | Building Sections π’ | Divides networks into smaller groups | Creating subnets with ip command |
| CIDR | Abbreviation βοΈ | Short way to write the mask | Quick notation in configs |
Think of it this way:
In Linux, all three work together! Here's how you see them:
When Linux wants to talk to another computer:
ip route - it shows how your computer decides where to send packets based on these masks!
Congratulations! You now understand the three amigos of Linux networking:
In Linux, they all work together to help your computer know: